/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.ast;

import alloy.type.UnionType;

/** Represents a let with an expr body. */

public class LetExpr extends LetImpl implements Expr {

    private static final UnionType DUMMY_TYPE = new UnionType();

	boolean _parens; 
	
    public LetExpr(Location location_, LetDecls letDecls_, Expr body_) {
        super(location_, letDecls_, body_);
    }

    public LetExpr(LetDecls letDecls_, Expr body_) {
        this(Location.UNKNOWN, letDecls_, body_);
    }

    /** get the formula of this. */
    public Expr getExpr() {
        return (Expr)getBody();
    }

    
    // NOTE: dummy get method -- the only time the type of 
    // the let will be asked for is if an error is encountered,
    // in which case get must always return the zero-sized UnionType
    public UnionType getType() {
        return DUMMY_TYPE;
    }
    
    // NOTE: dummy set method -- the only time the type of 
    // the let will be set is if an error is encountered,
    // in which case get must always return the zero-sized UnionType
    public void setType(UnionType type_) {}

	public boolean hasParens() {
		return _parens;
	}
	
	public void setParens(boolean parens_) {
		_parens = parens_;
	}
	    
    /**
     * accept an AST visitor
     * @param visitor_ the visitor
     */
    protected void acceptVisitor(ASTVisitor visitor_) {
        visitor_.visit(this);
    }

    /**
     * accept a returning AST visitor
     * @param visitor_ the visitor
     * @return the Object returned by the visitor
     */
    protected Object acceptReturnVisitor(ASTReturnVisitor visitor_) {
        return visitor_.visit(this);
    }

    public BinaryExpr join(Expr other_) {
        BinaryExpr ret = new BinaryExpr(this, BinaryExprOp.JOIN_DOT, other_);
        return ret;
    }

    public BinaryExpr union(Expr other_) {
        BinaryExpr ret = new BinaryExpr(this, BinaryExprOp.UNION, other_);
        return ret;
    }

    public BinaryExpr diff(Expr other_) {
        BinaryExpr ret = new BinaryExpr(this, BinaryExprOp.DIFF, other_);
        return ret;
    }

    public BinaryExpr intersect(Expr other_) {
        BinaryExpr ret = new BinaryExpr(this, BinaryExprOp.INTERSECT, other_);
        return ret;
    }

    public BinaryExpr override(Expr other_) {
        BinaryExpr ret = new BinaryExpr(this, BinaryExprOp.RELATIONALOVERRIDE, other_);
        return ret;
    }

    public BinaryExpr product(Expr other_) {
        BinaryExpr ret = new BinaryExpr(this, BinaryExprOp.RELATION, other_);
        return ret;
    }

    public ElemFormula in(Expr other_) {
        return new ElemFormula(this, CompOp.SUBSETIN, other_);
    }

    public ElemFormula eq(Expr other_) {
        return new ElemFormula(this, CompOp.EQUALS, other_);
    }

}
